import { defineComponent, reactive, onMounted } from 'vue'
import Draw from './draw'
import { getPriceVisuals } from '@/api/datavisual'

export default defineComponent({
  components: {
    Draw
  },
  setup(props,context) {
    const cdata = reactive({
      category: [],
      lineData: [],
      barData: [],
      rateData: []
    })

    const setData = (content: any) => {
      cdata.barData = []
      cdata.category = []
      content.forEach((v)=>{
        cdata.category.push(v.price);
        cdata.barData.push(v.num);
      })
    }

    context.expose({setPriceBarData: (data: any)=>{
        setData(data)
      }});

    // 生命周期
    onMounted(() => {
      getPriceVisuals().then((res)=>{
        if(res.code === '00000'){
          const data = res.data
          setData(data)
        }
      })
    })

    return () => {
      return <div>
        <Draw cdata={cdata} />
      </div>
    }
  }
})
